package edit;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

public class PSRulePane extends JScrollPane{
	private JPanel panel;
	private JRadioButton showName;
	private JRadioButton showDetail;
	private JComboBox category;
	private JTextField groupName;
	private JTextField ruleName;
	private String title;
	private JButton showStruc;
	private JButton newGrp;
	private JButton newConst;
	private JRadioButton showRule;
	private JRadioButton showRecord;
	
	public PSRulePane(String title){
		this.title = title;
		this.setBorder(BorderFactory.createTitledBorder(this.title));
		panel = new JPanel();  
		setViewportView(panel);
		panel.setLayout(null);
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		double width = screenSize.getWidth();
		double height = screenSize.getHeight();
		int palettewidth = (int)(width*0.4);
		int paletteheight = (int)(height*0.2);
		this.setPreferredSize(new Dimension(palettewidth,paletteheight));
		addComponents();
	}
	
	public void addComponents(){
		JLabel catLbl = new JLabel("Syntactic Category: ");
		JLabel groupLbl = new JLabel("Group Name: ");
		JLabel ruleLbl = new JLabel("Rule's Name: ");
		
		category = new JComboBox();
		groupName = new JTextField("");
		ruleName = new JTextField("");
		
		catLbl.setBounds(5, 5, 140, 20);
		category.setBounds(140, 5, 120, 20);
		category.setEnabled(false);
		
		groupLbl.setBounds(270, 5, 120, 20);
		groupName.setBounds(380, 5, 120, 20);
		ruleLbl.setBounds(5, 30, 120, 20);
		ruleName.setBounds(140, 30, 300, 20);
		
		showStruc = new JButton("Show Structure");
		showStruc.setBounds(5, 55, 120, 20);
		
		newConst = new JButton("Insert New Constituent into Rule");
		newConst.setBounds(127, 55, 200, 20);
		newGrp = new JButton("Insert New Group into Rule");
		newGrp.setBounds(330, 55, 200, 20);
		
		showRule = new JRadioButton("Show Rule");
		showRule.setBounds(5, 105, 120, 20);
		showRecord = new JRadioButton("Show Recorded Cooccurences");
		showRecord.setBounds(130, 105, 200, 20);
		ButtonGroup bgroup2 = new ButtonGroup();
		bgroup2.add(showRule);
		bgroup2.add(showRecord);
		
		
		showName = new JRadioButton("Show Name");
		showDetail = new JRadioButton("Show Detail");
		
		ButtonGroup bgroup = new ButtonGroup();
		bgroup.add(showName);
		bgroup.add(showDetail);
		showName.setBounds(5, 80, 120, 20);
		showDetail.setBounds(130, 80, 120, 20);
		
		panel.add(showRule);
		panel.add(showRecord);
		panel.add(newConst);
		panel.add(newGrp);
		panel.add(showStruc);
		panel.add(catLbl);
		panel.add(groupLbl);
		panel.add(ruleLbl);
		panel.add(category);
		panel.add(groupName);
		panel.add(ruleName);
		panel.add(showName);
		panel.add(showDetail);
		
		showStruc.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(showStruc.getLabel().equals("Show Structure"))
					showStruc.setLabel("Hide Structure");
				else
					showStruc.setLabel("Show Structure");
			}
			
		});
		
		
	}
	
	
}
